package com.hxut.controller;


import com.hxut.common.lang.Result;
import com.hxut.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description: TestController
 * date: 2022/6/21 9:04
 * author: MR.孙
 */
@RestController
@Slf4j
public class TestController {
    @Autowired
    private SysUserService userService;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/test")
    public Result test(){
        return Result.success(userService.list());
    }


    @PreAuthorize("hasAnyAuthority('sys:user:list')")
    @GetMapping("/test/pass")
    public Result pass(){
        String encodePassword = bCryptPasswordEncoder.encode("11111");
        log.info("当前11111加密后的编码为:",encodePassword);
        boolean flag = bCryptPasswordEncoder.matches(encodePassword, "11111");
        log.info("密码比对",flag);

        return Result.success(encodePassword);
    }
}
